package com.tanhua.server.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tanhua.common.mapper.JournalMapper;
import com.tanhua.server.service.JournalService;
import com.tanhua.server.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/manage")
@Slf4j
public class JournalController {

    @Autowired
    private JournalService journalService;

    @GetMapping("/logs")
    public ResponseEntity<PageResult> queryJournal(@RequestParam(value = "page",required = false) Integer page,
                                                     @RequestParam(value = "pagesize",required = false)Integer pagesize,
                                                     @RequestParam(value = "sortProp") String sortProp,
                                                     @RequestParam(value = "sortOrder") String sortOrder){
        try {
            PageResult pageResult = this.journalService.queryJournalList(page, pagesize, sortProp, sortOrder);

            if (ObjectUtil.isNotEmpty(pageResult)){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询用户信息出错~ ", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
